package org.edu.modules.system.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.edu.modules.system.entity.ProcessInstance;
import org.edu.modules.system.mapper.ProcessInstanceMapper;
import org.edu.modules.system.service.IProcessInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author lbh
 * @Date 2025/2/13 上午9:12
 * @Version 1.0
 */
@Slf4j
@Service
public class ProcessInstanceServiceImpl extends ServiceImpl<ProcessInstanceMapper, ProcessInstance> implements IProcessInstanceService {
    @Autowired
    private ProcessInstanceMapper processInstanceMapper;


    @Override
    public void approveProcess(Integer instanceId, String approverId, String approvalResult, String comment) {
        processInstanceMapper.approveProcess(instanceId, approverId, approvalResult, comment);
    }

    @Override
    public void resubmitProcess(Integer instanceId, String applicantId, String formData) {
        processInstanceMapper.resubmitProcess(instanceId, applicantId, formData);
    }

    @Override
    public void createProcess(Integer processTypeId, String applicantId, String formData) {
        processInstanceMapper.createProcess(processTypeId, applicantId, formData);
    }

    @Override
    public Map getProcessInstance(Integer instanceId) {
        return processInstanceMapper.getProcessInstance(instanceId);
    }

    @Override
    public Integer countDblc(String userId) {
        return processInstanceMapper.countDblc(userId);
    }


    @Override
    public Integer countYblc(String userId) {
        return processInstanceMapper.countYblc(userId);
    }
    @Override
    public Long countMyCreate(String paramJson,String userId) {
        return processInstanceMapper.countMyCreateInstance(userId,paramJson);
    }
    @Override
    public IPage<ProcessInstance> getMyApprovals(Page page ,String paramJson,String approveId) {
        // 查询分页数据
        IPage<ProcessInstance> list = processInstanceMapper.getMyApprovalsPage(page,paramJson,approveId,page.getCurrent(),page.getSize());
        Long total = processInstanceMapper.countMyApprovals(paramJson,approveId);
        list.setTotal(total);
        return list;
    }
    @Override
    public IPage<ProcessInstance> spGetDblcPage(Page page,String userId) {
        // 查询分页数据
        IPage<ProcessInstance> list = processInstanceMapper.spGetDblcPage(page,userId,page.getCurrent(),page.getSize());
        Integer total = processInstanceMapper.countDblc(userId);
        list.setTotal(total);
        return list;
    }
    @Override
    public IPage<ProcessInstance> spGetYblcPage(Page page ,String userId) {
        // 查询分页数据
        IPage<ProcessInstance> list = processInstanceMapper.spGetYblcPage(page,userId,page.getCurrent(),page.getSize());
        Integer total = processInstanceMapper.countYblc(userId);
        list.setTotal(total);
        return list;
    }
    @Override
    public IPage<ProcessInstance> getMyCreateProcess(Page page ,String paramJson,String userId) {
        // 查询分页数据
        IPage<ProcessInstance> list = processInstanceMapper.getMyCreateInstancePage(page,paramJson,page.getCurrent(),page.getSize());
        Long total = processInstanceMapper.countMyCreateInstance(userId,paramJson);
        list.setTotal(total);
        return list;
    }


    @Override
    public List<Map> countGroupByTypeId() {
        return processInstanceMapper.countGroupByTypeId();
    }
}
